﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using MobileClient.PublicFunctionClass;
using MobileClient.MobileClientBackgroundRef;

namespace MobileClient
{
    public partial class Login : System.Web.UI.Page
    {
        Ultimus_MobileServices services = new Ultimus_MobileServices();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                txtAccount.Focus();
                BingDomainList();
            }
        }

        private void BingDomainList()
        {
            try
            {
                string[] Domains = services.GetUltimusByAdministratorDomains();
                for (int i = 0; i < Domains.Length; i++)
                {
                    dropDomain.Items.Insert(i, new ListItem(Domains[i], Domains[i]));
                }
            }
            catch (Exception ex)
            {
                PublicClass.ShowMessage(this.Page, Resources.Resource.Login_ErrorMessage1);
                PublicClass.WriteLogOfTxt(ex.Message);
            }
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                string UserAccount = txtAccount.Text;
                string PassWord = txtPassWord.Text;
                string Domain = dropDomain.SelectedValue.Trim();
                UserInfo info = services.CheckUserByUltimus(Domain + "/" + UserAccount, PassWord);
                if (!String.IsNullOrEmpty(info.UserFullName))
                {
                    Session["UserInfo"] = info;
                    Response.Redirect("ToDoTask.aspx");
                }
                else
                {
                    PublicClass.ShowMessage(this.Page, Resources.Resource.Login_ErrorMessage3);
                }
            }
            catch (Exception ex)
            {
                PublicClass.ShowMessage(this.Page, Resources.Resource.Login_ErrorMessage2);
                PublicClass.WriteLogOfTxt(ex.Message);
            }
        }



    }
}